package com.dhwl.hsh.driver.ui.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;

import com.dhwl.hsh.lib.bean.resp.BannerResponse;

/**
 * 首页广告banner图片所在的fragment
 * @author Derek.Kidd
 * @time 2016/4/20 18:20
 */
public class BannerFragment extends Fragment
{

    private static final String KEY_CONTENT = "BannerFragment";

    private BannerResponse bannerResponse;

    
    private int resId;

    public static BannerFragment newInstants(Context context, int resId)
    {
        BannerFragment newPreFragment = new BannerFragment();
        newPreFragment.resId = resId;
        return newPreFragment;
    }
    
    public static BannerFragment newInstants(Context context, BannerResponse bannerResponse)
    {
        BannerFragment newPreFragment = new BannerFragment();
        newPreFragment.bannerResponse = bannerResponse;
        return newPreFragment;
    }
    

    
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        if ((savedInstanceState != null) && savedInstanceState.containsKey(KEY_CONTENT))
        {
            bannerResponse = (BannerResponse) savedInstanceState.getSerializable(KEY_CONTENT);
        }
        
    }
    
    @Override
    public void onSaveInstanceState(Bundle outState)
    {
        outState.putSerializable(KEY_CONTENT, bannerResponse);
    }
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        
        ImageView imageView = new ImageView(getActivity());
        imageView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        //FIT_XY 把图片不按比例扩大/缩小到View的大小显示
        imageView.setScaleType(ScaleType.FIT_XY);
        String filePath = null;
        if (null != bannerResponse)
        {
            filePath = bannerResponse.getAdCode();
        }
        else
        {
         // filePath = ;
        }

        imageView.setImageResource(resId);

        
        return imageView;
    }
}
